/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

/**
 * <p>Project: javase202202 - Arr6
 * <p>Powered by Lisi On 2022-06-06 09:31:58
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class Arr6 {
    public static void main(String[] args) {
        Integer[] nums = new Integer[10];
        //System.out.println(nums.length);
        //索引下标为10
        //System.out.println(nums[10]);
        //System.out.println(nums[0]);
        Random rand = new Random();
        for (int i = 0; i < nums.length; i++) {
            //rand.nextInt(start,end) 在jdk新版本中，有两个int参数的方法，可以返回指定范围，但不包括上限
            //返回1-100范围内的随机整数
            nums[i] = rand.nextInt(1, 101);
        }
        System.out.println(Arrays.toString(nums));
        //升序
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
        //a和b是形参数，lambda表达式

        //原始代码，对数组进行降序排序,b-a代表降 a-b升序
        Arrays.sort(nums, (a, b) -> b - a);
        System.out.println(Arrays.toString(nums));

        //乱序排序
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? 1 : -1);
        System.out.println(Arrays.toString(nums));
    }
}
